package com.jhd.fuzhou.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.RecyclerView;

import com.jhd.fuzhou.R;
import com.jhd.fuzhou.util.EditTextView;
import com.jhd.fuzhou.view.dossier.DossierActivity;
import com.jhd.fuzhou.view.login.FuzhouApplication;
import com.jhd.fuzhou.vo.ArchivesFileVo;
import com.jhd.fuzhou.vo.OrganizationVo;
import com.jhd.fuzhou.vo.SearchUnit;
import com.jhd.fuzhou.vo.Supervisor;

import java.util.List;

import static com.jhd.fuzhou.view.login.MainActivity.supervisionInspectionVo;

public class OrgAdapter extends RecyclerView.Adapter<OrgAdapter.ViewHolder> {
    private int checkPosition=-1;private List<OrganizationVo> organizationVoList;private Context context;
    private SearchUnit searchUnit;private String orgId;private FuzhouApplication application;

    public OrgAdapter(List<OrganizationVo> organizationVoList, SearchUnit searchUnit, FuzhouApplication application, Context context) {
        this.organizationVoList = organizationVoList;
        this.searchUnit = searchUnit;
        this.application = application;
        this.context = context;
    }
    @NonNull
    @Override
    public OrgAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_radio, parent, false);
        OrgAdapter.ViewHolder viewHolder = new OrgAdapter.ViewHolder(itemView);
        return viewHolder;
    }
    @Override
    public void onBindViewHolder(@NonNull OrgAdapter.ViewHolder holder, int position) {
        holder.rb_radio.setText(organizationVoList.get(position).getName());
        holder.rb_radio.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                checkPosition=position;
                application.setOrgId2(organizationVoList.get(position).getId());
                notifyDataSetChanged();
            }
        });
        if(position==checkPosition){
            holder.rb_radio.setChecked(true);
        }else{
            holder.rb_radio.setChecked(false);
        }
    }
    @Override
    public int getItemCount() {
        return organizationVoList.size();
    }
    class ViewHolder extends RecyclerView.ViewHolder {
        RadioButton rb_radio;
        public ViewHolder(View itemView) {
            super(itemView);
            this.rb_radio = itemView.findViewById(R.id.rb_radio);
        }
    }
}
